//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2013 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_FUNCTORS_TRANSFORM_CASE_H_
#define _BUOLA_FUNCTORS_TRANSFORM_CASE_H_

#include <buola/functors/transform/unary.h>
#include <buola/utility/ulocale.h>
#include <wctype.h>

namespace buola { namespace fn {

///\addtogroup transform
///@{

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// conversion-to-lowercase functor
///
/// Its `operator()` returns the lowercase version of its argument, computed using the `ctype`
/// facet of the given locale.
///
/// \tparam tChar the character type for which `operator()` will be called
///
/// The facet for converting the character type is cached for efficiency.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename tChar>
struct AToLower : public GUnaryTransform
{
    ///initializes with an optional locale parameter
    AToLower(const ULocale &pLocale=ULocale())
        :   mLocale(pLocale)
    {}
    
    ///returns the result of converting \p pCh to lowercase
    tChar operator()(tChar pCh) const
    {
        return towlower(pCh);
    }
    
private:
    ULocale mLocale;
};

/////////////////////////////////////////////////////////////////////////////////////////////////
///
/// conversion-to-uppercase functor
///
/// Its `operator()` returns the uppercase version of its argument, computed using the `ctype`
/// facet of the given locale.
///
/// \tparam tChar the character type for which `operator()` will be called
///
/// The facet for converting the character type is cached for efficiency.
///
/////////////////////////////////////////////////////////////////////////////////////////////////
template<typename tChar>
struct AToUpper : public GUnaryTransform
{
    ///initializes with an optional locale parameter
    AToUpper(const ULocale &pLocale=ULocale())
        :   mLocale(pLocale)
    {}
    
    ///returns the result of converting \p pCh to uppercase
    tChar operator()(tChar pCh) const
    {
        return towupper(pCh);
    }
    
private:
    ULocale mLocale;
};

///@}

/*namespace fn*/ } /*namespace buola*/ }

#endif
